package com.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.entity.Staff;
import com.service.StaffService;
import com.service.User1Service;

@Controller
public class controller1 {
	
	@Resource
	public User1Service user1Service;
	@Resource
	public StaffService staffService;
	
	public List<Staff> stafflist;
	
//	跳转到监控页面
	@RequestMapping("Monitor")
	public String Monitor(){
		
		return"Monitor";
	}


		/*功能一: 分页查询
		 * page  >>>>>  获取页面信息并分页
		 * 
		 * page2  >>>>  上一页
		 * 
		 * page3  >>>>  下一页
		 * 
		 * */	
	//  获取页面信息并分页
		@RequestMapping(value="page",method=RequestMethod.GET)
		public String page(Model model){
			stafflist = staffService.selefen(0);
			
			int ys=0;
			int ys1=1;
			model.addAttribute("stafflist", stafflist);
			model.addAttribute("ys", ys);
			model.addAttribute("ys1", ys1);
			return "page";
		}
//		上一页
		@RequestMapping(value="page2",method=RequestMethod.GET)
		public String page2(int ys,int ys1,Model model){
			
			stafflist = staffService.selefen(ys*5);
			
			if(ys==0){
				model.addAttribute("stafflist", stafflist);
				model.addAttribute("ys", ys);
				model.addAttribute("ys1", ys1);
				return "page";
			}
			ys1=ys1-1;
			ys=ys-1;
			model.addAttribute("stafflist", stafflist);
			model.addAttribute("ys", ys);
			model.addAttribute("ys1", ys1);
			return "page";
		}
		
//		下一页
		@RequestMapping(value="page3",method=RequestMethod.GET)
		public String page3(int ys,int ys1,Model model){
			stafflist = staffService.selefen(ys1*5);
			
			if(stafflist!=null&&!stafflist.isEmpty()){
				ys1=ys1+1;
				ys=ys+1;

				model.addAttribute("stafflist", stafflist);
				model.addAttribute("ys", ys);
				model.addAttribute("ys1", ys1);
				return "page";
				
				
			}else{
				model.addAttribute("stafflist", stafflist);
				model.addAttribute("ys", ys);
				model.addAttribute("ys1", ys1);
				model.addAttribute("ts", "没有计划了请返回上一页");
				return "page";
			}
			
		}
		
//		按条件查询
		@RequestMapping(value="select",method=RequestMethod.POST)
		public String select(String sname,String sjob,Model model){
			System.out.println(sname+sjob);
			
			stafflist = staffService.select(sname);
			
			model.addAttribute("stafflist", stafflist);
			
			return "page";
		}
}
